<!--  -->
<template>
    <div class="app-container">
        <div class="df">
            <el-button type="warning" icon="el-icon-edit" size="small" @click="add">添加</el-button>
        </div>
        <el-table :data="sliderData" border stripe>
            <template v-for="(i, index) in columns">
                <el-table-column
                    v-if="index == 1"
                    :prop="i.data"
                    :key="i.id"
                    :label="i.label"
                    align="center"
                    :width="i.width"
                >
                    <template slot-scope="scope">
                        <el-image
                            class="slideImg"
                            :src="scope.row.image"
                            fit="fill"
                            :lazy="true"
                            :previewSrcList="[scope.row.image]"
                        ></el-image>
                    </template>
                </el-table-column>
                <el-table-column
                    v-else-if="index == 5"
                    :prop="i.data"
                    :key="i.id"
                    :label="i.label"
                    align="center"
                    :width="i.width"
                >
                    <template slot-scope="scope">
                        <el-switch
                            v-model="scope.row.isUsed"
                            :active-value="true"
                            :inactive-value="false"
                            @change
                        ></el-switch>
                    </template>
                </el-table-column>
                <el-table-column
                    v-else
                    :prop="i.data"
                    :key="i.id"
                    :label="i.label"
                    align="center"
                    :width="i.width"
                ></el-table-column>
            </template>
            <el-table-column align="center" label="操作" width="200">
                <template slot-scope="scope">
                    <el-button type="text" icon="el-icon-edit" @click="edit(scope)">编辑</el-button>
                    <el-button
                        type="text"
                        icon="el-icon-delete"
                        style="color: #ff6666"
                        @click="del(scope)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="page">
            <el-pagination
                @size-change="sizeChange"
                @current-change="currentChange"
                :current-page.sync="page"
                :page-sizes="[20, 40, 80, 100]"
                :page-size="limit"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                background
            ></el-pagination>
        </div>

        <!-- 对话框 -->
        <el-dialog
            :title="dialogTitle"
            :visible.sync="showDialog"
            width="40%"
            @close="showDialog = false"
        >
            <el-form
                :model="form"
                ref="form"
                :rules="rules"
                label-width="80px"
                :inline="false"
                size="normal"
                class="iBox"
            >
                <el-form-item label="编号" prop="id">
                    <el-input v-model="form.id"></el-input>
                </el-form-item>
                <el-form-item label="邀请类型" prop="type">
                    <el-input v-model="form.type"></el-input>
                </el-form-item>
                <el-form-item label="邀请海报" prop="cover">
                    <el-input v-model="form.cover"></el-input>
                </el-form-item>
                <el-form-item label="邀请名称" prop="name">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="邀请文案" prop="content">
                    <el-input v-model="form.content"></el-input>
                </el-form-item>
                <el-form-item label="是否启用" prop="isUsed">
                    <el-input v-model="form.isUsed"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="">立即创建</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "slider",
    data () {
        return {
            time: "",
            dialogTitle: "创建",
            showDialog: false,
            page: 1,
            limit: 10,
            total: 10,
            form: {},
            sliderData: [
                {
                    id: "1",
                    image:
                        "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
                    introduce: "说明1说明1说明1说明1说明1说明1",
                    herfType: "了解了解了解了解",
                    sortOrder: 1,
                    isUsed: true
                },
                {
                    id: "2",
                    image:
                        "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
                    introduce: "说明1说明1说明1说明1说明1说明1说明1",
                    herfType: "了解了解了解了解",
                    sortOrder: 2,
                    isUsed: true
                },
                {
                    id: "3",
                    image:
                        "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
                    introduce: "说明3说明1说明1说明1说明1说明1",
                    herfType: "了解了解了解了解",
                    sortOrder: 3,
                    isUsed: true
                }
            ],
            rules: {

            },
            columns: [
                { key: 0, label: `编号`, data: "id", visible: true, width: "80" },
                { key: 1, label: `邀请海报`, data: "image", visible: true },
                { key: 2, label: `邀请名称`, data: "introduce", visible: true },
                { key: 2, label: `邀请类型`, data: "sortOrder", visible: true, width: "100" },
                { key: 3, label: `邀请文案`, data: "herfType", visible: true, width: "250" },
                { key: 4, label: `是否启用`, data: "isUsed", visible: true, width: "100" }
            ]
        };
    },
    methods: {
        add () { },
        edit () {
            this.showDialog = true;
        },
        del () { },
        sizeChange () { },
        currentChange () { }
    }
};
</script>
<style scoped>
.df {
    margin-bottom: 15px;
}
.slideImg {
    width: 140px;
}
.iBox .el-input {
    width: 60%;
}
</style>
